package command 
{
	import cn.inswf.framework.mvcs.Command;
	import flash.display.DisplayObjectContainer;
	import flash.display.Loader;
	import flash.display.Shape;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	import view.InfoView;
	/**
	 * ...
	 * @author lee
	 */
	public class XmlDataLoadedCommand extends Command 
	{
		
		[Inject]public var _container:DisplayObjectContainer;
		public function XmlDataLoadedCommand() 
		{
			
		}
		override public function execute():void 
		{
			State.chapter = State.lesson = 0;
			var bgconfig:String = Config.getParam("bg");
			if (bgconfig != "") {
				var color:int = -1;
				if (bgconfig.indexOf("#") == 0) {
					color = Number("0x"+bgconfig.substr(1));
				}else if (bgconfig.indexOf("0x") != -1) {
					color = Number(bgconfig);
				}else if (bgconfig.indexOf(".") != -1) {
					color = -1;
				}
				if (color != -1) {
					var sh:Shape = new Shape();
					sh.graphics.beginFill(color);
					sh.graphics.drawRect(0, 0, _container.stage.stageWidth, _container.stage.stageHeight);
					sh.graphics.endFill();
					_container.stage.addChildAt(sh,0);
				}else {
					var loader:Loader = new Loader();
					_container.stage.addChildAt(loader,0);
					loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loader_ioError);
					loader.load(new URLRequest(bgconfig));
				}
			}
			_container.addChild(getInstance(InfoView));
		}
		
		private function loader_ioError(e:IOErrorEvent):void 
		{
			
		}
	}

}